package com.wc.AlgoOJ.DS0208;

import java.io.*;
import java.util.*;

/**
 * @Author congge
 * @Date 2023/12/8 9:13
 * 光头强学数组
 * http://43.138.190.70:8888/p/DS0208
 * @description
 */
public class Main {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static Map<Integer, ArrayList<Integer>> map = new HashMap<>();

    public static void main(String[] args) {
        int n = Integer.parseInt(nextLine());
//        pw.println(n);
        while (n-- > 0) {
            String[] op = nextLine().split(" ");
            int arrNum = Integer.parseInt(op[1]);
            if (op[0].equals("push")) {
                int num = Integer.parseInt(op[2]);
                push(arrNum,num);
            } else if (op[0].equals("show")) {
                show(arrNum);
            } else {
                clear(arrNum);
            }
        }

        pw.flush();
        pw.close();
    }

    public static void push(int arrNum,int num){
        if (!map.containsKey(arrNum)) {
            map.put(arrNum, new ArrayList<>());
        }
        ArrayList<Integer> curArr = map.get(arrNum);
        curArr.add(num);
        pw.println(curArr.size());
    }

    public static void show(int arrNum) {
        ArrayList<Integer> arrayList = map.get(arrNum);
        if (arrayList == null || arrayList.size() == 0) {
            pw.println("null");
            return;
        }
        int size = arrayList.size();
        pw.print(arrayList.get(0));
        for (int i = 1; i < size; i++) {
            pw.print(' ');
            pw.print(arrayList.get(i));
        }
        pw.println();
    }


    public static void clear(int arrNum){
        ArrayList<Integer> arrayList = map.get(arrNum);
        if (arrayList == null || arrayList.size() == 0) {
            pw.println(0);
            return;
        }
        pw.println(arrayList.size());
        arrayList.clear();
    }

    public static String nextLine() {
        String s = "";
        try {
            s = reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }
}
